<template>
  <view class="bg">
    <image class="img" mode="scaleToFill" src="@/static/images/bg.png"></image>
    <view class="code-box">
      <image
        class="code"
        mode="scaleToFill"
        src="@/static/images/sao.png"
        @click="scanCode"
      ></image>
      <view class="tip">扫一扫二维码</view>
    </view>

  </view>
    <AuthOverlay ref="authOverlayRef"></AuthOverlay>
</template>

<script setup>
import { getToken } from '@/utils/auth';
const authOverlayRef = ref(null);
function scanCode() {
  if (!getToken()) {
    authOverlayRef.value.show = true;
    return;
  }
  uni.scanCode({
    // onlyFromCamera: true,
    // scanType: ["barCode", "qrCode"],
    success: (res) => {
      console.log("res", res);
      // 调取接口
      // this.qrcode = res.result; // this.show = "二维码类型:" + res.scanType + "字符集:" + res.charSet + "路径:" + res.path+"结果:" + res.result;
      // this.qrcode = res.path; // this.show = "二维码类型:" + res.scanType + "字符集:" + res.charSet + "路径:" + res.path+"结果:" + res.result;
      const path = res.path.split("?")[0];
      const scene = res.path.split("?")[1];
      let params = decodeURIComponent(scene);
      const id = params.split("=")[2];
      uni.navigateTo({
        url: `/${path}?id=${id}`,
      });
      // postDeviceInfo({
      //   deviceNo: res.result,
      // }).then((data) => {
      //   uni.navigateTo({
      //     url: `/${path}?id=${id}`,
      //   });
      // });

      // setTimeout(() => {
      //   this.getEquIdStatus();
      // }, 2000);
    },
    fail(e) {
      uni.showToast({
        icon: "none",
        title: "扫码失败",
      });
      // uni.navigateTo({
      //   url: "/pages/home/package",
      // });
    },
  });
}
</script>

<style lang="scss" scoped>
.bg {
  position: relative;
  width: 100vw;
  height: 100vh;

  .img {
    width: 100%;
    height: 100%;
  }

  .code-box {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 488rpx;
    height: 488rpx;
    transform: translate(-50%, -50%);

    .code {
      width: 100%;
      height: 100%;
    }

    .tip {
      margin-top: 46rpx;
      font-size: 40rpx;
      text-align: center;
      color: #fff;
      font-weight: 600;
      line-height: 56rpx;
    }
  }
}
</style>
